home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / editors / emcs1857 / 1857el~1.zoo / lisp / keypad.el < prev    next >
Encoding:
Text File  |  1992-02-04  |  5.9 KB  |  159 lines

  1. ;; Terminal-independent keypad and function key bindings.
  2. ;; Copyright (C) 1986, 1990 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 1, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  18. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.  
  21. ;; Modified 1990 for 8-bit character support by Howard Gayle.
  22. ;; See case-table.el for details.
  23.  
  24.  
  25. ;; These keys are handled by a two-level process.
  26. ;; The first level, terminal-dependent, maps input sequences
  27. ;; into the function keys that they represent.
  28. ;; The second level, terminal-independent but customized by users,
  29. ;; map function keys into meanings.
  30.  
  31. ;; This file takes care of the second level of mapping.
  32. ;; The first, terminal-dependent, level is handled by the
  33. ;; terminal-specific files term/*.el.
  34.  
  35. ;; The second-level mapping is done by a keymap, function-keymap.
  36. ;; Here we document the meanings of the "characters" defined by
  37. ;; function-keymap.
  38.  
  39. ;; What do these letters mean?
  40. ;; When we say that ``a stands for the clear-all-tabs key'',
  41. ;; we mean that you should attach to the letter `a' in function-keymap
  42. ;; whatever command you want to be executed when you type the
  43. ;; clear-all-tabs key on any terminal.  The terminal-dependent
  44. ;; files will attempt to make this work.  If a terminal has no
  45. ;; clear-all-tabs key that can be recognized, it makes no difference
  46. ;; what binding you give to `a' in function-keymap.
  47.  
  48. ;; a -- clear all tabs key
  49. ;; b -- tabulation backward
  50. ;; c -- erase key
  51. ;; d -- down-arrow
  52. ;; e -- enter key
  53. ;; f -- find key or search key
  54. ;; h -- home-position key
  55. ;; k -- delete key or remove key.
  56. ;; l -- left-arrow
  57. ;; p -- portrait mode
  58. ;; q -- landscape mode
  59. ;; r -- right-arrow
  60. ;; s -- select key
  61. ;; t -- clear tab this column key
  62. ;; u -- up-arrow
  63. ;; x -- do key
  64. ;; ? -- help
  65.  
  66. ;; - -- keypad key labelled `-'.
  67. ;; . -- keypad key labelled `.'.
  68. ;; , -- keypad key labelled `,'.
  69. ;; 0 ... 9 -- keypad key labelled with that digit,
  70. ;;   but only if that key is not also an arrow key.
  71.  
  72. ;; C-@, C-a, ... C-x -- numbered function keys 0 through 24.
  73. ;; These are used for function keys with no labels but numbers,
  74. ;; and may also be used for function keys with labels
  75. ;; that we have not defined letters for.
  76.  
  77. ;; A -- insert line key
  78. ;; C -- clear screen key
  79. ;; D -- delete character key.
  80. ;; E -- clear to end of line key
  81. ;; F -- scroll forward key
  82. ;; H -- home-down
  83. ;; I -- insert character key
  84. ;;       If there is just an "insert" key, it should be this.
  85. ;; L -- delete line key
  86. ;; M -- exit insert mode key
  87. ;; N -- next page key
  88. ;; P -- previous page key
  89. ;; R -- scroll reverse key
  90. ;; S -- clear to end of screen key
  91. ;; T -- set tab this column key
  92.  
  93. (defun keypad-default (char definition)
  94.   (or (lookup-key function-keymap char)
  95.       (define-key function-keymap char definition)))
  96.  
  97. ;; Here are the standard command meanings we give to the various
  98. ;; function key names.  Because this file is loaded after the user's
  99. ;; init file, we are careful to avoid overriding any definitions
  100. ;; already stored in function-keymap by the init file or (less often)
  101. ;; by the terminal-specific term/*.el file.
  102.  
  103. (keypad-default "l" 'backward-char)
  104. (keypad-default "r" 'forward-char)
  105. (keypad-default "D" 'delete-char)
  106. (keypad-default "u" 'previous-line)
  107. (keypad-default "d" 'next-line)
  108. (keypad-default "N" 'scroll-up)
  109. (keypad-default "P" 'scroll-down)
  110. (keypad-default "C" 'recenter)
  111. (keypad-default "?" 'help-for-help)
  112. (keypad-default "s" 'set-mark-command)
  113. (keypad-default "k" 'kill-region)
  114. (keypad-default "f" 're-search-forward)
  115.  
  116. (keypad-default "\C-a" 'beginning-of-line)
  117. (keypad-default "\C-b" 'end-of-line)
  118. (keypad-default "\C-c" 'isearch-forward)
  119. (keypad-default "\C-d" 'kill-line)
  120.  
  121. (keypad-default "." 'delete-char)
  122. (keypad-default "0" 'yank)
  123. (keypad-default "e" 'open-line)
  124. (keypad-default "1" 'backward-word)
  125. (keypad-default "3" 'forward-word)
  126. (keypad-default "7" 'backward-paragraph)
  127. (keypad-default "9" 'forward-paragraph)
  128. (keypad-default "h" 'move-to-window-line)
  129.  
  130. (defun setup-terminal-keymap (map translations)
  131.   "Set up keymap MAP to forward to function-keymap according to TRANSLATIONS.
  132. TRANSLATIONS is an alist; each element of it looks like (FROMSTRING . TOCHAR).
  133. For each such pair, we define the key sequence FROMSTRING in MAP
  134. to forward to the definition of character TOCHAR in function-keymap.
  135. \"Forwarding\" means that subsequent redefinition of TOCHAR in
  136. function-keymap will be seen automatically in MAP as well.
  137.  
  138. This function is used by files term/*.el to set up the mapping from the
  139. escape sequences sent by function keys on particular terminals (FROMSTRINGs)
  140. into Emacs standard function key slots (TOCHARs).
  141. An actual definition (such as a symbol) may be given in place of TOCHAR.
  142. Generally, MAP is a prefix keymap which will be attached to a key
  143. that is the common prefix sent by all function keys (often ESC O or ESC [)."
  144.   (let (b c)
  145.     (while translations
  146.       (setq b (car translations)) ; A (string . char) pair.
  147.       (setq c (cdr b)) ; The char (or a function).
  148.       (define-key map (car b)
  149.         (if (numberp c) (lookup-key function-keymap (char-to-string c)) c))
  150.       (setq translations (cdr translations)))))
  151.  
  152. (defun function-key-sequence (char)
  153.   "Return key sequence for function key that on this terminal
  154. translates into slot CHAR in function-keymap.
  155. Or return nil if there is none."
  156.   (car (where-is-internal (cons function-keymap char) (current-local-map))))
  157.  
  158. (provide 'keypad)
  159.